/*
 * Quercia Luciano
 * Algoritmi e Strutture Dati
 * a.a. 2009-10
 */


#include <iostream>
using namespace std;

#include "pila.h"

int main() {
   typedef Pila<int> Stack;

   Stack stack;

   stack.printAll();
   stack.inPila(1);
   stack.printAll();
   stack.inPila(2);
   stack.printAll();
   stack.inPila(3);
   stack.printAll();
   stack.inPila(4);
   stack.printAll();
   stack.inPila(5);
   stack.printAll();

   try {
	   stack.fuoriPila();
	   stack.printAll();
	   stack.fuoriPila();
	   stack.printAll();
	   stack.fuoriPila();
	   stack.printAll();
	   stack.fuoriPila();
	   stack.printAll();
	   stack.fuoriPila();
	   stack.printAll(); //Empty

	   //Pila Vuota - eccezione sollevata
	   stack.fuoriPila();
	   stack.printAll();

   } catch (char const *msg) {
	   cout << msg;
   }

stack.inPila(1);
stack.inPila(2);
stack.inPila(3);
stack.inPila(4);

int k = 0;

while (! stack.pilaVuota() ){
	k += stack.leggiPila();
	stack.fuoriPila();
}

cout << endl << "La somma vale: " << k << endl;


   return 0;
}
